package com.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

public class MyErrorFilter extends ZuulFilter{

	public Object run() {		
		System.out.println("in MyErrorFilter, type is error");
		RequestContext context = RequestContext.getCurrentContext();
		
		Throwable throwable = context.getThrowable();		
		throwable.printStackTrace();		
		
		context.setResponseBody("Error happens.");
		
		return null;
	}

	public boolean shouldFilter() {
		return true;
	}

	@Override
	public int filterOrder() {
		return 1;
	}

	@Override
	public String filterType() {
		return "error";
	}

}
